package com.itheima.activiti.service.system.impl;

import cn.hutool.core.bean.BeanUtil;
import com.itheima.activiti.dto.system.RoleDTO;
import com.itheima.activiti.service.system.RoleService;
import com.itheima.authority.api.v1.RoleApi;
import com.itheima.authority.common.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleApi roleApi;

    /**
     * 获取所有权限列表，用于：
     * 设计流程图中选择角色
     * @return
     */
    @Override
    public List<RoleDTO> list() {
        R<List<com.itheima.authority.api.v1.dto.RoleDTO>> roleResult = roleApi.list(null);
        List<RoleDTO> roleDTOList = new ArrayList<>();
        if (roleResult.getIsSuccess()) {
            for (com.itheima.authority.api.v1.dto.RoleDTO datum : roleResult.getData()) {
                RoleDTO roleDTO = new RoleDTO();
                BeanUtil.copyProperties(datum, roleDTO);
                roleDTOList.add(roleDTO);
            }
        }
        return roleDTOList;
    }

}
